// pages/wode/share.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:[],
    page:1,
    limit:50,
    empty:false,
    isLoadingAll:false,
    keywords:'',
    type:1,
    status:{
      '0':'待授权',
      '1':'已授权',
      '-1':'已取消',
      '-2':'已拒绝'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(this.data.status[-1])
    this.getList()
  },

  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      lists:[],
      page:1,
      empty:false,
      isLoadingAll:false,
    })
    this.getList()

    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(!this.data.isLoadingAll){
      this.data.page++
      this.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  tab:function(e){
    var that=this
    var type=e.currentTarget.dataset.type

    that.setData({
      type:type,
      lists:[],
      page:1,
      empty:false,
      isLoadingAll:false,
      keywords:''
    })
    this.getList()
    
  },

  getData:function(){
    var that=this
    var userInfo=wx.getStorageSync('userInfo')
    var data={}
    data.id=userInfo.storeId
    app.agriknow.commRequest('ht/store/incomeTopData',data).then(res=>{
      console.log(res)
      var datas=res.data
      datas.dayPrice=datas.dayPrice.toFixed(2)
      datas.weekPrice=datas.weekPrice.toFixed(2)
      datas.mouthPrice=datas.mouthPrice.toFixed(2)
      that.setData({
        countData:datas
      })
     
   })

  },

  getList:function(){
    var that=this
    var userInfo=wx.getStorageSync('userInfo')
    var data={}
    data.storeId=userInfo.storeId
    data.page=this.data.page
    data.limit=this.data.limit
    data.type=this.data.type
    if(this.data.keywords){
      data.keywords=this.data.keywords
    }
  
    app.getList('ht/store/shareList',data,that)
  },
  cancelDelete:function(e){
    var that=this
    var data={}
    var id=e.currentTarget.dataset.id
    var type=e.currentTarget.dataset.type
    var userInfo=wx.getStorageSync('userInfo')
    data.storeId=userInfo.storeId
    data.id=id
    data.type=type
    var text={}
    if(type==1){
      text.content="确定取消"
      text.tips="取消成功"
    }else if(type==2){
      text.content="确定删除"
      text.tips="删除成功"
    }
    wx.showModal({
      title: '提示',
      content: text.content,
      success (res) {
        if (res.confirm) {
          app.agriknow.commRequest('ht/store/shareApplyAdmin',data).then(res=>{
            if(res.code=='000000'){
              that.tipsMessage(text.tips)
              that.refresh()
            }else{
              that.tipsMessage(res.data)
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  adoptRefuse:function(e){
    var that=this
    var data={}
    var id=e.currentTarget.dataset.id
    var type=e.currentTarget.dataset.type
    var userInfo=wx.getStorageSync('userInfo')
    data.storeId=userInfo.storeId
    data.id=id
    data.type=type
    var text={}
    if(type==1){
      text.content="确定授权"
      text.tips="授权成功"
    }else if(type==2){
      text.content="确定拒绝"
      text.tips="成功拒绝"
    }
    wx.showModal({
      title: '提示',
      content: text.content,
      success (res) {
        if (res.confirm) {
          app.agriknow.commRequest('ht/store/shareAuthAdmin',data).then(res=>{
            if(res.code=='000000'){
              that.tipsMessage(text.tips)
              that.refresh()
            }else{
              that.tipsMessage(res.data)
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  //提示信息
  tipsMessage(text) {
    wx.showToast({
      title: text,
      icon: 'none',
      duration: 2000,
      mask: true
    })

  },

  refresh:function(){
    this.setData({
      lists:[],
      page:1,
      empty:false,
      isLoadingAll:false,
    })
    this.getList()
  }


})